import requests
from gevent import thread

cookies = {
    '_ga': 'GA1.2.1116089687.1639475294',
    'org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE': 'zh-HK',
    'venueNature': '0',
    'session': '.eJwNzDEOwyAMAMC_MFaNZMDGkM9UxjEdUkGktENU9e9lveG-TlTtPB_vsVt3qwtFBQiieBDPmSiCqcZWOG0pmN085tpai4UlxII5oUeWRLVOoMzu7sZhfWny0tEX3Wd6faRfoz-PsVrcWFGNaf7eNHutFAgBJIEhuN8fhvArFg.FbmF8Q.tuf7PSB1dXcgt_mTcrHMbRrtFSI',
    'CART_SERIAL_NUM': 'KSK01_1658371206659',
    'selectedIndex': '1',
    'homeUrl': '/purchase/top_sellers',
}

headers = {
    'Connection': 'keep-alive',
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"',
    'X-Locale': 'zh_HK',
    'Accept-Language': 'zh_HK',
    'sec-ch-ua-mobile': '?0',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36',
    'X-DeviceCode': 'KSK01',
    'Content-Type': 'application/json;charset=UTF-8',
    'Accept': 'application/json, text/plain, */*',
    'sec-ch-ua-platform': '"macOS"',
    'Origin': 'https://hkkiosk-pub.maoyan.team',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Dest': 'empty',
    'Referer': 'https://hkkiosk-pub.maoyan.team/purchase/top_sellers',
    # Requests sorts cookies= alphabetically
    # 'Cookie': '_ga=GA1.2.1116089687.1639475294; org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=zh-HK; venueNature=0; session=.eJwNzDEOwyAMAMC_MFaNZMDGkM9UxjEdUkGktENU9e9lveG-TlTtPB_vsVt3qwtFBQiieBDPmSiCqcZWOG0pmN085tpai4UlxII5oUeWRLVOoMzu7sZhfWny0tEX3Wd6faRfoz-PsVrcWFGNaf7eNHutFAgBJIEhuN8fhvArFg.FbmF8Q.tuf7PSB1dXcgt_mTcrHMbRrtFSI; CART_SERIAL_NUM=KSK01_1658371206659; selectedIndex=1; homeUrl=/purchase/top_sellers',
}

params = {
    'locale': 'zh_HK',
}

json_data = {
    'sortFields': [
        {
            'name': 'performance_date_start',
            'asc': True,
        },
        {
            'name': 'event_name_en.keyword',
            'asc': True,
        },
    ],
    'pageSize': 6,
    'pageNo': 1,
}
a=0
while a < 200:

    # thread.sleep(1)
    response = requests.post('https://hkkiosk-pub.maoyan.team/api/v1/events/queryTopSellers', params=params,
                             cookies=cookies, headers=headers, json=json_data)
    print(response.text)
